package com.Lyf.manager.controller;


import com.Lyf.common.vo.ResultVO;
import com.Lyf.manager.entity.Admin;
import com.Lyf.manager.service.ManagerService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/manager")
@Slf4j
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    @PostMapping("/login")
    public ResultVO login(String username, String password, HttpSession session,String captcha) {
        log.info("接收");
        //step1:处理验证码

        //拿到session中存放的验证码
        String sessionCaptcha = (String) session.getAttribute("captcha");
        if(captcha == null || !captcha.equals(sessionCaptcha)) {
            return ResultVO.error("验证码错误");
        }

        //step2:调用登录接口
        Admin admin= managerService.login(username,password);
        if(admin == null) {
            return ResultVO.error("所登录用户不存在");
        }
        return ResultVO.success();
    }


}
